//
//  PersonDataManager.h
//  VISIKARD
//
//  Created by Admin on 5/24/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
#import "Define.h"
#import <MapKit/MapKit.h>
#import "SDWebImageManager.h"

#define STRING_CODER_USER_DATA_PERSON_DATA_PERSON_NAME                  @"STRING_CODER_USER_DATA_PERSON_DATA_PERSON_NAME"
#define STRING_CODER_USER_DATA_PERSON_DATA_PERSON_ID                    @"STRING_CODER_USER_DATA_PERSON_DATA_PERSON_ID"
#define STRING_CODER_USER_DATA_PERSON_DATA_CATEGORY_ARRAY               @"STRING_CODER_USER_DATA_PERSON_DATA_CATEGORY_ARRAY"

typedef enum {
    enumIsDataMine_Invalid,
    enumIsDataMine_isMine,
    enumIsDataMine_isMyKard,
    enumIsDataMine_isMyDeal
}enumIsDataMine;

typedef enum {
    eHasNotChild = 0,
    eChildIsNode,
    eChildIsCategory,
    eChildIsCategoryAndNode
}enumChildOfCategory;

typedef enum {
    eIsDataAddInvalid = -1,
    eIsDataAddNull,
    eIsDataAddHasSameNameInAGroup,
    eIsDataAddHasSameIdInAGroup,
    eIsDataAddSearchContinue,
    eIsDataAddSearchFail,
    eIsDataAddFailChildIsNode,
    eIsDataAddFailChildIsCategory,
    eIsDataAddSuccess
}enumIsDataAdd;

typedef enum {
    enumIsDataRemove_Invalid,
    enumIsDataRemove_DataIsNil,
    enumIsDataRemove_Continuous,
    enumIsDataRemove_NotExist,
    enumIsDataRemove_Successful
}enumIsDataRemove;

typedef enum {
    enumIsLocalCopyType_Invalid,
    enumIsLocalCopyType_FromServer,
    enumIsLocalCopyType_Copy,
    enumIsLocalCopyType_Move
}enumIsLocalCopyType;

typedef enum {
    enumPersonGender_Invalid,
    enumPersonGender_Male,
    enumPersonGender_Female
}enumPersonGender;

@interface PersonNodeData : NSObject <MKAnnotation, SDWebImageManagerDelegate> {
    NSString                                        *personName;
    NSString                                        *personID;
    UIImage                                         *personSmallAvatar;
    UIImage                                         *personMediumAvatar;
    UIImage                                         *personLargeAvatar;
    NSString                                        *personSmallAvatarURL;
    NSString                                        *personMediumAvatarURL;
    NSString                                        *personLargeAvatarURL;
}
- (id)initWithPersonName:(NSString *)strName
             andPersonID:(NSString *)strID
    andPersonSmallAvatar:(UIImage *)imgSmallAvatar;

@property (nonatomic, retain) NSString                  *personName;
@property (nonatomic, retain) NSString                  *personID;
@property (nonatomic, retain) UIImage                   *personSmallAvatar;
@property (nonatomic, retain) UIImage                   *personMediumAvatar;
@property (nonatomic, retain) UIImage                   *personLargeAvatar;
@property (nonatomic, retain) NSString                  *personSmallAvatarURL;
@property (nonatomic, retain) NSString                  *personMediumAvatarURL;
@property (nonatomic, retain) NSString                  *personLargeAvatarURL;
@property (nonatomic, assign) enumPersonGender          personGender;
@property (nonatomic) enumIsLocalCopyType               isLocalCopyType;

@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString                  *titletext;
@property (nonatomic, retain) NSString                  *subtitletext;

@property (nonatomic, retain) NSString                  *personPhongDepStatus;
@property (nonatomic, retain) NSString                  *personPhongDepArea;
@property (nonatomic, retain) NSString                  *personPhongDepPrice;
@property (nonatomic, retain) NSString                  *personPhongDepAddress;
@property (nonatomic, retain) NSString                  *personPhongDepDistrict;
@property (nonatomic, retain) NSString                  *personPhongDepCity;

- (NSString *)subtitle;
- (NSString *)title;
- (void)setTitle:(NSString*)strTitle;
- (void)setSubTitle:(NSString*)strSubTitle;
- (id)getPropertyWithKey:(NSString *)key;

@end

@interface PersonCategoryData : PersonNodeData {
@private
    NSMutableArray                      *categoryArray;
    unsigned int                        personDeepLevel;
    BOOL                                isHidden;
    enumChildOfCategory                 isChildOfCategory;
}
- (enumIsDataAdd)addNode:(PersonNodeData *)node;
- (enumIsDataAdd)addNode:(PersonNodeData *)node atPersonID:(NSString *)strID;
- (enumIsDataAdd)addCategory:(PersonCategoryData *)node;
- (enumIsDataAdd)addCategory:(PersonCategoryData *)node atPersonID:(NSString *)strID;
- (NSMutableArray *)AllCategoriesWithPersonID:(NSString *)strID;
- (NSMutableArray *)AllKardsWithPersonID:(NSString *)strId;

- (BOOL)checkImInhere:(PersonNodeData *)node;
- (enumIsDataRemove)removeCategoriesWithPersonID:(NSString *)strID;
- (enumIsDataRemove)removePersonWithPersonID:(NSString *)strID;
- (enumIsDataRemove)removeCategories:(PersonCategoryData *)node;
- (enumIsDataRemove)removePerson:(PersonNodeData *)node;
- (enumIsDataRemove)removeDataFromServer;
- (void)resetAllData;

@property (nonatomic) unsigned int  personDeepLevel;
@property (nonatomic, readonly) enumChildOfCategory isChildOfCategory;
@property (nonatomic, readonly) BOOL isHidden;
@property (nonatomic, readonly) NSMutableArray *AllNode;
@property (nonatomic, readonly) NSMutableArray *CurrentCategory;
@property (nonatomic, readonly) NSMutableArray *CurrentNode;
@property (nonatomic, readonly) NSMutableArray *categoryArray;

@end

@interface PersonTableData : NSObject {
@private
    NSMutableArray      *categoryArray;
}
@property (nonatomic, readonly) NSMutableArray *AllNode;
@property (nonatomic, readonly) NSMutableArray *CurrentCategory;
@property (nonatomic, readonly) NSMutableArray *CurrentNode;
@property (nonatomic, readonly) NSMutableArray *categoryArray;
- (NSMutableArray *)AllCategoriesWithPersonID:(NSString *)strID;
- (NSMutableArray *)AllKardsWithPersonID:(NSString *)strID;
- (enumIsDataAdd)addNode:(PersonNodeData *)node;
- (enumIsDataAdd)addNode:(PersonNodeData *)node atPersonID:(NSString *)strID;
- (enumIsDataAdd)addCategory:(PersonCategoryData *)node atPersonID:(NSString *)strID;
- (enumIsDataAdd)addCategory:(PersonCategoryData *)node;

- (enumIsDataRemove)removeCategoriesWithPersonID:(NSString *)strID;
- (enumIsDataRemove)removePersonWithPersonID:(NSString *)strID;
- (void)resetAllData;
- (enumIsDataRemove)removeCategories:(PersonCategoryData *)node;
- (enumIsDataRemove)removePerson:(PersonNodeData *)node;
- (enumIsDataRemove)removeDataFromServer;

@end

@interface PersonDataManager : NSObject {
    PersonTableData      *rootData;
}
@property (nonatomic, readonly) NSMutableArray *AllNode;
@property (nonatomic, readonly) NSMutableArray *CurrentCategory;
@property (nonatomic, readonly) NSMutableArray *CurrentNode;
@property (nonatomic, readonly) NSMutableArray *categoryArray;
- (enumIsDataAdd)addCategory:(PersonCategoryData *)node;
- (enumIsDataAdd)addCategory:(PersonCategoryData *)node atPersonID:(NSString *)strID;
- (enumIsDataAdd)addNode:(PersonNodeData *)node;
- (enumIsDataAdd)addNode:(PersonNodeData *)node atPersonID:(NSString *)strID;
- (NSMutableArray *)AllCategoriesWithPersonID:(NSString *)strID;
- (NSMutableArray *)AllKardsWithPersonID:(NSString *)strID;

- (enumIsDataRemove)removeCategoriesWithPersonID:(NSString *)strID;
- (enumIsDataRemove)removePersonWithPersonID:(NSString *)strID;
- (void)resetAllData;
- (enumIsDataRemove)removeCategories:(PersonCategoryData *)node;
- (enumIsDataRemove)removePerson:(PersonNodeData *)node;
- (enumIsDataRemove)removeDataFromServer;

+ (PersonDataManager *)roomsShared;
+ (PersonDataManager *)housesShared;

@end
